﻿/////////////////////////////////////////////////
//文件名:SortTable
//描  述:
//创建者:刘凡平(Iveely Liu)
//邮  箱:945222889@qq.com
//组  织:Iveely
//年  份:2012/5/26 11:12:59
///////////////////////////////////////////////


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace IveelySE.BigData.Common.DataStruct
{
    /// <summary>
    /// 排序表
    /// </summary>
    [Serializable]
    public class SortTable : Hashtable
    {
        /// <summary>
        /// 关键字列
        /// </summary>
        private ArrayList list = new ArrayList();
        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="value">值</param>
        public override void Add(object key, object value)
        {
            base.Add(key, value);
            list.Add(key);
        }
        /// <summary>
        /// 清除所有数据
        /// </summary>
        public override void Clear()
        {
            base.Clear();
            list.Clear();
        }
        /// <summary>
        /// 移除数据
        /// </summary>
        /// <param name="key">关键字</param>
        public override void Remove(object key)
        {
            base.Remove(key);
            list.Remove(key);
        }



        /// <summary>
        /// 获取指定位置间的值域
        /// </summary>
        /// <param name="startPlace">起始位置</param>
        /// <param name="endPlace">结束位置</param>
        /// <returns>返回值域集</returns>
        public List<object> GetValues(double key)
        {
            int start = -1;
            int end = -1;
            for (int i = 0, j =list.Count - 1; i < j; i++, j--)
            {
                if ((double)list[i] > key && (double)list[i] < key+1 && start < 0)
                {
                    start = i;
                }
                if ((double)list[j] > key && (double)list[j] < key+1 && end < 0)
                {
                    end = j;
                }
            }

            //新建返回列表
            List<object> result = new List<object>();
            for (int i = start ; i < end + 1; i++)
            {
                result.Add(this[list[i]]);
            }
            return result;
        }
       

        public override ICollection Keys
        {
            get
            {
                return list;
            }
        }
    }
}
